package pl.elka.simulator.core;

import java.util.List;

public class AreaConstraint extends Constraint{

	public AreaConstraint() {
		super();		
	}
	public AreaConstraint(List<Position> edges) {
		super(edges);		
	}
	public boolean contains(float px,float py) {
		boolean c = false;
		int nvert = edges.size();
		Position vertC = null;
		Position vertP = null;
		
		for (int i = 0, j = nvert-1; i < nvert; j = i++) {
			vertC = edges.get(i);
			vertP = edges.get(j);

			if ( ((vertC.getY()>py) != (vertP.getY()>py)) &&
				(px < (vertP.getX()-vertC.getX()) * (py-vertC.getY()) / (vertP.getY()-vertC.getY()) + vertC.getX()) )
			   c = !c;
		}
		
		return !c;
	}	
}
